<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Funciones para obtener la informacion de los perfiles
 *
 * @author Haydee
 */
class View_Helper_ProfileHelper extends Model3_View_Helper
{
    const PROFILE_EDIT=1;
    const PROFILE_REGISTER=2;

    /**
     * Muestra la info del perfil de usuario 
     * @param DefaultDb_Entities_User $user1 
     */
    public function getProfile($user1, $user2 = null)
    {
        echo '<div class="profileHeader" >';
        echo '<div class="profileImage" >';
        if ($user1->getHeadShot() != '')
        {
            echo '<div style="width: 150px; height: 150px; overflow: hidden;" >';
            echo '<img alt="HeadShot" src="' . $this->_view->url(array('controller' => 'FixImages', 'action' => 'index', '0' => $user1->getId())) . '" /><br/>';
            echo '</div>';
        }
        else
            echo '<img alt="HeadShot" src="' . $this->_view->getBaseUrl() . '/images/nopic.jpg" /><br/>';
        echo '</div>';
        echo '<span class="profileName" >' . $user1->getFirstName() . ' ' . $user1->getLastName() . '</span><br/>';
        if ($user1->getTitle() != '')
            echo $user1->getTitle() . '<br/>';
        echo $user1->getCompany() . '<br/>';
        if ($user1->getCompanyUrl() != NULL)
            echo '<a class="link" href="http://' . $user1->getCompanyUrl() . '" target="_blank" >' . $user1->getCompanyUrl() . '</a><br/>';
        if($user1->getCountry())
            echo htmlentities($user1->getCountry()->getNameCountry()). '<br/>'; 
        echo $user1->getCellPhone() . '<br/>';
        echo $user1->getLocalNumber() . '<br/>';
        echo '<div>';
        echo '</div>';
        echo '</div>';
        echo '<hr/>';
        ?>

        <div>
            <strong>Geographical Areas:</strong><br/>
            <?php
            foreach ($user1->getAreasGeographicals() as $userArea)
                echo $userArea->getNameArea() . '<br/>';
            ?>
        </div>
        <br/>
        <strong>Services:</strong><br/>
        <div class="span-24">
            <div class="span-8 last">
                <?php
                foreach ($user1->getServices() as $userService)
                    echo $userService->getNameService() . '<br/>';
                ?>
            </div>
        </div>
        <div style="margin-top: 10px;" class="span-8 last">
            <strong>Interests:</strong><br/>
            <?php
            switch ($user1->getTypeUSer())
            {
                case DefaultDb_Entities_User::TYPE_BUYER:
                    echo "Buyer";
                    break;
                case DefaultDb_Entities_User::TYPE_BOTH:
                    echo "Both (Buyer Seller)";
                    break;
                case DefaultDb_Entities_User::TYPE_SELLER:
                    echo "Seller";
                    break;
                case DefaultDb_Entities_User::TYPE_NEITHER:
                    echo "Neither (Buyer Seller)";
                    break;
            }
            ?>
        </div>
        <br/>

        <?php
        if ($user1->getDescription() != '')
        {
            echo '<strong>Description:</strong>';
            echo '<div style="border: none;">';
            echo $user1->getDescription();
            echo '</div>';
        }

        if (count($user1->getGeneratedDocumentsUser()) > 0)
        {
            echo '<strong>Documents:</strong><br/>';
            foreach ($user1->getGeneratedDocumentsUser() as $doc)
            {
                echo '<a href="' . $this->_view->getBaseUrl() . '/' . $doc->getDocument() . '" target="_blank">' . $doc->getDocumentDescription() . '</a>';
                echo '<br>';
            }
        }

        if ($user1->getLinkFacebook() != NULL || $user1->getLinkLinkedIn() != NULL || $user1->getLinkMySpace() != NULL || $user1->getLinkTwitter() != NULL)
            echo '<strong>Social Networks:</strong><br/><br/>';
        if ($user1->getLinkFacebook() != NULL)
            echo '<div style="float:left; margin-right: 5px;"><img width="22px" alt="Facebook" src="' . $this->_view->getBaseUrl() . '/images/ui/Facebook-48.png"/></div>&nbsp;<a class="link" target="_blank" href="' . $user1->getLinkFacebook() . '">' . $user1->getLinkFacebook() . '</a><br/><br/>';
        if ($user1->getLinkLinkedIn() != NULL)
            echo '<div style="float:left; margin-right: 5px;"><img width="22px" alt="LinkedIn" src="' . $this->_view->getBaseUrl() . '/images/ui/LinkedIn-48.png"/></div>&nbsp;<a class="link" target="_blank" href="' . $user1->getLinkLinkedIn() . '">' . $user1->getLinkLinkedIn() . '</a><br/><br/>';
        if ($user1->getLinkMySpace() != NULL)
            echo '<div style="float:left; margin-right: 5px;"><img width="22px" alt="MySpace" src="' . $this->_view->getBaseUrl() . '/images/ui/Myspace-48.png"/></div>&nbsp;<a class="link" target="_blank" href="' . $user1->getLinkMySpace() . '">' . $user1->getLinkMySpace() . '</a><br/><br/>';
        if ($user1->getLinkTwitter() != NULL)
            echo '<div style="float:left; margin-right: 5px;"><img width="22px" alt="Twitter" src="' . $this->_view->getBaseUrl() . '/images/ui/Twitter 1-48.png"/></div>&nbsp;<a class="link" target="_blank" href="' . $user1->getLinkTwitter() . '">' . $user1->getLinkTwitter() . '</a><br/><br/>';


        if (Model3_Auth::getCredentials('type_login_user') == 2)
        {
            if ($user2 != null && $user2->getId() !== $user1->getId())
            {
                
                if ($user1->getAllowRequests())
                    echo '<a  href="' . $this->_view->url(array('controller' => 'Calendar', 'action' => 'invite', 'user' => $user1->getId())) . '">Invite</a><br/>';
                echo '<a  href="' . $this->_view->url(array('controller' => 'Message', 'action' => 'sendMessage', 'user' => $user1->getId())) . '">Send Message</a><br/>';
                if (!$user2->hasFavorite($user1))
                    echo '<a  href="' . $this->_view->url(array('controller' => 'Favorites', 'action' => 'add', 'user' => $user1->getId())) . '">Add to favorites</a>';
            }
        }
    }

    /* @var $user DefaultDb_Entities_User */

    public function editSaveProfile($action=self::PROFILE_REGISTER, $user=null)
    {
        $edit = ($action == self::PROFILE_EDIT) ? true : false;
        ?>
        <form id="register" method="post" action="<?php echo $this->_view->url(); ?>" enctype="multipart/form-data">
            <div>
                <table class="sTable" style="width: 100%">
                    <tr><td width="25%">Email: *</td><td width="35%"><input <?php echo ($edit) ? 'disabled="disabled"' : ''; ?> type="text" id="email" name="email" value="<?php echo ($edit) ? $user->getUsername() : ''; ?>"/></td><td></td></tr>
                    <?php if (!$edit): ?>
                    <tr><td>Contrase&ntilde;a: * </td><td><input type="password" id="pass" name="pass" value="" /></td><td></td></tr>
                    <tr><td>Confirme contrase&ntilde;a:* </td><td><input type="password" id="confirmation" name="confirmation" value="" /></td><td></td></tr>
                    <?php endif; ?>
                    <tr><td>Nombre(s): * </td><td><input type="text" id="firstName" name="firstName" value="<?php echo ($edit) ? $user->getFirstName() : ''; ?>"/></td><td></td></tr>
                    <tr><td>Apellido Paterno: * </td><td><input type="text" id="lastName" name="lastName" value="<?php echo ($edit) ? $user->getLastName() : ''; ?> "/></td><td></td></tr>
                    <tr><td>Ciudad: * </td>
                        <td>
                            <select id="country" name="country"> 
                            <?php
                            foreach($this->_view->countries as $country)
                            {
                                $selected = "";
                                if($edit && $user->getCity()->getId() == $country->getId())
                                    $selected = ' selected = "selected" ';
                                echo '<option value="' . $country->getId() .'" '.$selected.'>'. $country->getNameCity() .'</option>';
                            }
                            ?>
                            </select>
                        </td>
                            <td></td></tr>
                </table>
                <br/>
            </div>
              * - Mandatory field <br/>
            <br/><br/>
            <?php if (!$edit): ?>
                <input type="checkbox" id="" name="" checked="checked" />Accept <a>Terms of Use</a><br/><br/>
                <input class="smartButton" type="submit" value="Register" />
            <?php else: ?>
                <br/>
                <input class="smartButton" type="submit" value="Save changes" />
            <?php endif; ?>
        </form>


        <?php
    }

}

